﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevComponents.DotNetBar;
using DAL;
using Table_Dal;
using BLL;
namespace ApplicationLayer
{
    public partial class frmCauHoi : DevComponents.DotNetBar.OfficeForm
    {
        string user="";
        public frmCauHoi(string username)
        {
            user = username;
            InitializeComponent();
        }

        private void frmCauHoi_Load(object sender, EventArgs e)
        {
            lblThoigian.Text = "";
            load_ComboMonHoc();
            loadcboChuong();
            
        }
        public void load_ComboMonHoc()
        {
            cboxMonHoc.DataSource = null;
            MonHocBLL mh = new MonHocBLL();
            int x = mh.LayTatCaMonHoc().Count;
            List<MonHocTbl> lst = new List<MonHocTbl>();
            lst = mh.LayTatCaMonHoc();
            if (lst.Count > 0)
            {
                cboxMonHoc.DataSource = lst;
                cboxMonHoc.DisplayMember = "TenMonHoc";
                cboxMonHoc.ValueMember = "MaMonHoc";
            }
            if (lst.Count > 0)
            {
                cboxMonHoc.SelectedIndex = 0;
            }
            else cboxMonHoc.Text = "";
        }
        
        
        private void cboxMonHoc_SelectedIndexChanged(object sender, EventArgs e)
        {
            loadcboChuong();
        }

        private void loadcboChuong()
        {
            if (cboxMonHoc.DataSource == null || cboxMonHoc.Items.Count == 0)
                return;
            cboChuong.DataSource = null;

            ChuongBll ch = new ChuongBll();
            List<ChuongTbl> DSChuong = new List<ChuongTbl>();
            MonHocBLL mh = new MonHocBLL();

            DSChuong = ch.DSChuong_MaMon(cboxMonHoc.SelectedValue.ToString());
            int Dem = DSChuong.Count;
            if (Dem == 0)
            {
                cboChuong.Text = "";
                return;
            }
            cboChuong.DataSource = DSChuong;
            cboChuong.DisplayMember = "TenChuong";
            cboChuong.ValueMember = "MaChuong";
            if (DSChuong.Count > 0)
            {
                cboChuong.SelectedIndex = 0;
            }
            else
                cboChuong.Text = "";
        }
        
        private void RatingDoKho_RatingChanged(object sender, EventArgs e)
        {
            
            
        }
        public void Load_listCauhoi()
        {
            if (cboChuong.Text == ""||cboChuong.DataSource ==null) return;
            int count = listCauHoi.Items.Count;
            if (count > 0)
                for (int x = count - 1; x >= 0; x--)
                {
                    listCauHoi.Items.RemoveAt(x);
                }
            if (cboChuong.Text == null || cboChuong.Text == "" || cboChuong.DataSource == null)
                return;
            List<CauHoiTbl> DsCauhoi = new List<CauHoiTbl>();

            CauHoiBll ch = new CauHoiBll();
            DsCauhoi = ch.LayDanhSachCauHoi_MaChuong_DoKho_MaMon(((ChuongTbl)cboChuong.SelectedItem).MaChuong, "Tất cả",((MonHocTbl)cboxMonHoc.SelectedItem).MaMonHoc);
            int Dem = DsCauhoi.Count;
            if (Dem == 0) return;
            for (int x = 0; x < Dem; x++)
            {
                ListViewItem lst = new ListViewItem();
                lst.Text = DsCauhoi[x].MaCauHoi.ToString();
                lst.SubItems.Add(DsCauhoi[x].NoiDung);
                listCauHoi.Items.Add(lst);
            }
        }
        private void cboChuong_SelectedIndexChanged(object sender, EventArgs e)
        {
            Load_listCauhoi();
            if (listCauHoi.SelectedItems.Count == 0 || listCauHoi.SelectedItems.Count > 1)
            {
                pic_A.Visible = false;
                pic_B.Visible = false;
                pic_C.Visible = false;
                pic_D.Visible = false;
                pic_E.Visible = false;
                pic_F.Visible = false;
                pic_Question.Visible = false;
                txtCauA.Text = "";
                txtCauB.Text = "";
                txtCauC.Text = "";
                txtCauD.Text = "";
                txtCauE.Text = "";
                txtCauF.Text = "";
                txtQuestion.Text = "";

                return;
            }
        }
        
        private void listCauHoi_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (listCauHoi.SelectedItems.Count == 0 || listCauHoi.SelectedItems.Count > 1)
            {
                pic_A.Visible = false;
                pic_B.Visible = false;
                pic_C.Visible = false;
                pic_D.Visible = false;
                pic_E.Visible = false;
                pic_F.Visible = false;
                pic_Question.Visible = false;
                txtCauA.Text = "";
                txtCauB.Text = "";
                txtCauC.Text = "";
                txtCauD.Text = "";
                txtCauE.Text = "";
                txtCauF.Text = "";
                txtQuestion.Text = "";

                return;
            }
            ListViewItem itemCauHoi = listCauHoi.SelectedItems[0];
            CauHoiBll ch = new CauHoiBll();
            CauHoiTbl chtbl = new CauHoiTbl();
            chtbl = ch.ThongTinCauHoi_TheoMaCauHoi_TenCauHoi(itemCauHoi.Text,"");
            txtQuestion.Text = chtbl.NoiDung;
            if (chtbl.HinhAnh != null && chtbl.HinhAnh != "")
            {
                pic_Question.ImageLocation = chtbl.HinhAnh;
                pic_Question.Visible = true;
            }
            else
            {
                pic_Question.ImageLocation = "";
                pic_Question.Visible = false;
            }
            RatingDoKho.Rating = chtbl.DoKho;
            if (RatingDoKho.Rating == 5)
            {
                lbl_DoKho.Text = "Rất khó";
                lbl_DoKho.ForeColor = Color.Fuchsia;
            }
            if (RatingDoKho.Rating == 4)
            {
                lbl_DoKho.Text = "Khó";
                lbl_DoKho.ForeColor = Color.Red;
            }
            if (RatingDoKho.Rating == 3)
            {
                lbl_DoKho.Text = "Vừa";
                lbl_DoKho.ForeColor = Color.Blue;
            }
            if (RatingDoKho.Rating == 2)
            {
                lbl_DoKho.Text = "Dễ";
                lbl_DoKho.ForeColor = Color.Green;
            } if (RatingDoKho.Rating == 1)
            {
                lbl_DoKho.Text = "Rất Dễ";
                lbl_DoKho.ForeColor = Color.Black;
            }
            if (RatingDoKho.Rating == 0)
            {
                lbl_DoKho.Text = "";
            }
            lblThoigian.Text = chtbl.ThoiGian.ToString();
            Load_DapAn("");
        }
        public void Load_DapAn(string s)
        {
            string Ma = "";
            if (s != "")
            {
                Ma = s;
            }
            else
            {
                ListViewItem itemCauHoi = listCauHoi.SelectedItems[0];
                Ma = itemCauHoi.Text;
            }
            
            int soDapan = 0;
            DapAnBll dapan = new DapAnBll();
            List<DapAnTbl> DsdapAn = new List<DapAnTbl>();
            DsdapAn = dapan.DapAnCauHoi_TheoMacauHoi_TenCauHoi(Ma, "");
            soDapan = DsdapAn.Count;
            if (soDapan < 2)
                return;

            if (soDapan == 2)
            {
                pnlDapanC.Visible = false;
                pnlDapanD.Visible = false;
                pnlDapanE.Visible = false;
                pnlDapanF.Visible = false;

                txtCauA.Text = DsdapAn[0].NoiDung;
                if (DsdapAn[0].LoaiDA == 1)
                {
                    txtCauA.ForeColor = Color.Red;
                    txtCauA.Font = new Font(txtCauA.Font, FontStyle.Bold);
                    
                }
                else
                {
                    txtCauA.Font = new Font(txtCauA.Font, FontStyle.Regular);
                    txtCauA.ForeColor = Color.SeaGreen;
                }
                txtCauB.Text = DsdapAn[1].NoiDung;
                txtCauB.Text = DsdapAn[1].NoiDung;
                if (DsdapAn[1].LoaiDA == 1)
                {
                    txtCauB.ForeColor = Color.Red;
                    txtCauB.Font = new Font(txtCauB.Font, FontStyle.Bold);
                }
                else
                {
                    txtCauB.Font = new Font(txtCauB.Font, FontStyle.Regular);
                    txtCauB.ForeColor = Color.SeaGreen;
                }
                //-------------------------------
                if( DsdapAn[0].HinhAnh!=null &&DsdapAn[0].HinhAnh!="")
                {
                    pic_A.ImageLocation = DsdapAn[0].HinhAnh;
                    pic_A.Visible = true;
                }
                else
                {
                    pic_A.ImageLocation = "";
                    pic_A.Visible = false;
                }
                if (DsdapAn[1].HinhAnh != null && DsdapAn[1].HinhAnh != "")
                {
                    pic_B.ImageLocation = DsdapAn[1].HinhAnh;
                    pic_B.Visible = true;
                }
                else
                {
                    pic_B.ImageLocation = "";
                    pic_B.Visible = false;
                }
                //-------------------------------
            }
            if (soDapan == 3)
            {
                pnlDapanC.Visible = true;
                pnlDapanD.Visible = false;
                pnlDapanE.Visible = false;
                pnlDapanF.Visible = false;

                txtCauA.Text = DsdapAn[0].NoiDung;
                txtCauA.Text = DsdapAn[0].NoiDung;
                if (DsdapAn[0].LoaiDA == 1)
                {
                    txtCauA.Font = new Font(txtCauA.Font, FontStyle.Bold);
                    txtCauA.ForeColor = Color.Red;
                }
                else
                {
                    txtCauA.Font = new Font(txtCauA.Font, FontStyle.Regular);
                    txtCauA.ForeColor = Color.SeaGreen;
                }
                txtCauB.Text = DsdapAn[1].NoiDung;
                txtCauB.Text = DsdapAn[1].NoiDung;
                if (DsdapAn[1].LoaiDA == 1)
                {
                    txtCauB.Font = new Font(txtCauB.Font, FontStyle.Bold);
                    txtCauB.ForeColor = new Color();
                    txtCauB.ForeColor = Color.SeaGreen;
                }
                else
                {
                    txtCauB.Font = new Font(txtCauB.Font, FontStyle.Regular);
                    txtCauB.ForeColor = Color.SeaGreen;
                }
                txtCauC.Text = DsdapAn[2].NoiDung;
                txtCauC.Text = DsdapAn[2].NoiDung;
                if (DsdapAn[2].LoaiDA == 1)
                {
                    txtCauC.Font = new Font(txtCauC.Font, FontStyle.Bold);
                    txtCauC.ForeColor = Color.Red;
                }
                else
                {
                    txtCauC.Font = new Font(txtCauC.Font, FontStyle.Regular);
                    txtCauC.ForeColor = Color.SeaGreen;
                }
                //-------------------------------
                if (DsdapAn[0].HinhAnh != null && DsdapAn[0].HinhAnh != "")
                {
                    pic_A.ImageLocation = DsdapAn[0].HinhAnh;
                    pic_A.Visible = true;
                }
                else
                {
                    pic_A.ImageLocation = "";
                    pic_A.Visible = false;
                }
                if (DsdapAn[1].HinhAnh != null && DsdapAn[1].HinhAnh != "")
                {
                    pic_B.ImageLocation = DsdapAn[1].HinhAnh;
                    pic_B.Visible = true;
                }
                else
                {
                    pic_B.ImageLocation = "";
                    pic_B.Visible = false;
                }
                if (DsdapAn[2].HinhAnh != null && DsdapAn[2].HinhAnh != "")
                {
                    pic_C.ImageLocation = DsdapAn[2].HinhAnh;
                    pic_C.Visible = true;
                }
                else
                {
                    pic_C.ImageLocation = "";
                    pic_C.Visible = false;
                }
                //-------------------------------
            }
            if (soDapan == 4)
            {
                pnlDapanC.Visible = true;
                pnlDapanD.Visible = true;
                pnlDapanE.Visible = false;
                pnlDapanF.Visible = false;

                txtCauA.Text = DsdapAn[0].NoiDung;
                txtCauA.Text = DsdapAn[0].NoiDung;
                if (DsdapAn[0].LoaiDA == 1)
                {
                    txtCauA.Font = new Font(txtCauA.Font, FontStyle.Bold);
                    txtCauA.ForeColor = new Color();
                    txtCauA.ForeColor = Color.SeaGreen;
                }
                else
                {
                    txtCauA.Font = new Font(txtCauA.Font, FontStyle.Regular);
                    txtCauA.ForeColor = Color.SeaGreen;
                }
                txtCauB.Text = DsdapAn[1].NoiDung;
                txtCauB.Text = DsdapAn[1].NoiDung;
                if (DsdapAn[1].LoaiDA == 1)
                {
                    txtCauB.Font = new Font(txtCauB.Font, FontStyle.Bold);
                    txtCauB.ForeColor = Color.Red;
                }
                else
                {
                    txtCauB.Font = new Font(txtCauB.Font, FontStyle.Regular);
                    txtCauB.ForeColor = Color.SeaGreen;
                }
                txtCauC.Text = DsdapAn[2].NoiDung;
                txtCauC.Text = DsdapAn[2].NoiDung;
                if (DsdapAn[2].LoaiDA == 1)
                {
                    txtCauC.Font = new Font(txtCauC.Font, FontStyle.Bold);
                    txtCauC.ForeColor = Color.Red;
                }
                else
                {
                    txtCauC.Font = new Font(txtCauC.Font, FontStyle.Regular);
                    txtCauC.ForeColor = Color.SeaGreen;
                }
                txtCauD.Text = DsdapAn[3].NoiDung;
                txtCauD.Text = DsdapAn[3].NoiDung;
                if (DsdapAn[3].LoaiDA == 1)
                {
                    txtCauD.Font = new Font(txtCauD.Font, FontStyle.Bold);
                    txtCauD.ForeColor = Color.Red;
                }
                else
                {
                    txtCauD.Font = new Font(txtCauD.Font, FontStyle.Regular);
                    txtCauD.ForeColor = Color.SeaGreen;
                }
                //-------------------------------
                if (DsdapAn[0].HinhAnh != null && DsdapAn[0].HinhAnh != "")
                {
                    pic_A.ImageLocation = DsdapAn[0].HinhAnh;
                    pic_A.Visible = true;
                }
                else
                {
                    pic_A.ImageLocation = "";
                    pic_A.Visible = false;
                }
                if (DsdapAn[1].HinhAnh != null && DsdapAn[1].HinhAnh != "")
                {
                    pic_B.ImageLocation = DsdapAn[1].HinhAnh;
                    pic_B.Visible = true;
                }
                else
                {
                    pic_B.ImageLocation = "";
                    pic_B.Visible = false;
                }
                if (DsdapAn[2].HinhAnh != null && DsdapAn[2].HinhAnh != "")
                {
                    pic_C.ImageLocation = DsdapAn[2].HinhAnh;
                    pic_C.Visible = true;
                }
                else
                {
                    pic_C.ImageLocation = "";
                    pic_C.Visible = false;
                }
                if (DsdapAn[3].HinhAnh != null && DsdapAn[3].HinhAnh != "")
                {
                    pic_D.ImageLocation = DsdapAn[3].HinhAnh;
                    pic_D.Visible = true;
                }
                else
                {
                    pic_D.ImageLocation = "";
                    pic_D.Visible = false;
                }
                //-------------------------------
            }
            if (soDapan == 5)
            {
                pnlDapanC.Visible = true;
                pnlDapanD.Visible = true;
                pnlDapanE.Visible = true;
                pnlDapanF.Visible = false;

                txtCauA.Text = DsdapAn[0].NoiDung;
                txtCauA.Text = DsdapAn[0].NoiDung;
                if (DsdapAn[0].LoaiDA == 1)
                {
                    txtCauA.Font = new Font(txtCauA.Font, FontStyle.Bold);
                    txtCauA.ForeColor = Color.Red;
                }
                else
                {
                    txtCauA.Font = new Font(txtCauA.Font, FontStyle.Regular);
                    txtCauA.ForeColor = Color.SeaGreen;
                }
                txtCauB.Text = DsdapAn[1].NoiDung;
                txtCauB.Text = DsdapAn[1].NoiDung;
                if (DsdapAn[1].LoaiDA == 1)
                {
                    txtCauB.Font = new Font(txtCauB.Font, FontStyle.Bold);
                    txtCauB.ForeColor = Color.Red;
                }
                else
                {
                    txtCauB.Font = new Font(txtCauB.Font, FontStyle.Regular);
                    txtCauB.ForeColor = Color.SeaGreen;
                }
                txtCauC.Text = DsdapAn[2].NoiDung;
                txtCauC.Text = DsdapAn[2].NoiDung;
                if (DsdapAn[2].LoaiDA == 1)
                {
                    txtCauC.Font = new Font(txtCauC.Font, FontStyle.Bold);
                    txtCauC.ForeColor = Color.Red;
                }
                else
                {
                    txtCauC.Font = new Font(txtCauC.Font, FontStyle.Regular);
                    txtCauC.ForeColor = Color.SeaGreen;
                }
                txtCauD.Text = DsdapAn[3].NoiDung;
                txtCauD.Text = DsdapAn[3].NoiDung;
                if (DsdapAn[3].LoaiDA == 1)
                {
                    txtCauD.Font = new Font(txtCauD.Font, FontStyle.Bold);
                    txtCauD.ForeColor = Color.Red;
                }
                else
                {
                    txtCauD.Font = new Font(txtCauD.Font, FontStyle.Regular);
                    txtCauD.ForeColor = Color.SeaGreen;
                }
                txtCauE.Text = DsdapAn[4].NoiDung;
                txtCauE.Text = DsdapAn[4].NoiDung;
                if (DsdapAn[4].LoaiDA == 1)
                {
                    txtCauE.Font = new Font(txtCauE.Font, FontStyle.Bold);
                    txtCauE.ForeColor = Color.Red;
                }
                else
                {
                    txtCauE.Font = new Font(txtCauE.Font, FontStyle.Regular);
                    txtCauE.ForeColor = Color.SeaGreen;
                }
                //-------------------------------
                if (DsdapAn[0].HinhAnh != null && DsdapAn[0].HinhAnh != "")
                {
                    pic_A.ImageLocation = DsdapAn[0].HinhAnh;
                    pic_A.Visible = true;
                }
                else
                {
                    pic_A.ImageLocation = "";
                    pic_A.Visible = false;
                }
                if (DsdapAn[1].HinhAnh != null && DsdapAn[1].HinhAnh != "")
                {
                    pic_B.ImageLocation = DsdapAn[1].HinhAnh;
                    pic_B.Visible = true;
                }
                else
                {
                    pic_B.ImageLocation = "";
                    pic_B.Visible = false;
                }
                if (DsdapAn[2].HinhAnh != null && DsdapAn[2].HinhAnh != "")
                {
                    pic_C.ImageLocation = DsdapAn[2].HinhAnh;
                    pic_C.Visible = true;
                }
                else
                {
                    pic_C.ImageLocation = "";
                    pic_C.Visible = false;
                }
                if (DsdapAn[3].HinhAnh != null && DsdapAn[3].HinhAnh != "")
                {
                    pic_D.ImageLocation = DsdapAn[3].HinhAnh;
                    pic_D.Visible = true;
                }
                else
                {
                    pic_D.ImageLocation = "";
                    pic_D.Visible = false;
                }
                if (DsdapAn[4].HinhAnh != null && DsdapAn[4].HinhAnh != "")
                {
                    pic_E.ImageLocation = DsdapAn[4].HinhAnh;
                    pic_E.Visible = true;
                }
                else
                {
                    pic_E.ImageLocation = "";
                    pic_E.Visible = false;
                }
                //-------------------------------
            }
            if (soDapan == 6)
            {
                pnlDapanC.Visible = true;
                pnlDapanD.Visible = true;
                pnlDapanE.Visible = true;
                pnlDapanF.Visible = true;
                txtCauA.Text = DsdapAn[0].NoiDung;
                txtCauA.Text = DsdapAn[0].NoiDung;
                if (DsdapAn[0].LoaiDA == 1)
                {
                    txtCauA.Font = new Font(txtCauA.Font, FontStyle.Bold);
                    txtCauA.ForeColor = Color.Red;
                }
                else
                {
                    txtCauA.Font = new Font(txtCauA.Font, FontStyle.Regular);
                    txtCauA.ForeColor = Color.SeaGreen;
                }
                txtCauB.Text = DsdapAn[1].NoiDung;
                txtCauB.Text = DsdapAn[1].NoiDung;
                if (DsdapAn[1].LoaiDA == 1)
                {
                    txtCauB.Font = new Font(txtCauB.Font, FontStyle.Bold);
                    txtCauB.ForeColor = Color.Red;
                }
                else
                {
                    txtCauB.Font = new Font(txtCauB.Font, FontStyle.Regular);
                    txtCauB.ForeColor = Color.SeaGreen;
                }
                txtCauC.Text = DsdapAn[2].NoiDung;
                txtCauC.Text = DsdapAn[2].NoiDung;
                if (DsdapAn[2].LoaiDA == 1)
                {
                    txtCauC.Font = new Font(txtCauC.Font, FontStyle.Bold);
                    txtCauC.ForeColor = Color.Red;
                }
                else
                {
                    txtCauC.Font = new Font(txtCauC.Font, FontStyle.Regular);
                    txtCauC.ForeColor = Color.SeaGreen;
                }
                txtCauD.Text = DsdapAn[3].NoiDung;
                txtCauD.Text = DsdapAn[3].NoiDung;
                if (DsdapAn[3].LoaiDA == 1)
                {
                    txtCauD.Font = new Font(txtCauD.Font, FontStyle.Bold);
                    txtCauD.ForeColor = Color.Red;
                }
                else
                {
                    txtCauD.Font = new Font(txtCauD.Font, FontStyle.Regular);
                    txtCauD.ForeColor = Color.SeaGreen;
                }
                txtCauE.Text = DsdapAn[4].NoiDung;
                txtCauE.Text = DsdapAn[4].NoiDung;
                if (DsdapAn[4].LoaiDA == 1)
                {
                    txtCauE.Font = new Font(txtCauE.Font, FontStyle.Bold);
                    txtCauE.ForeColor = Color.Red;
                }
                else
                {
                    txtCauE.Font = new Font(txtCauE.Font, FontStyle.Regular);
                    txtCauE.ForeColor = Color.SeaGreen;
                }
                txtCauF.Text = DsdapAn[5].NoiDung;
                txtCauF.Text = DsdapAn[5].NoiDung;
                if (DsdapAn[5].LoaiDA == 1)
                {
                    txtCauF.Font = new Font(txtCauF.Font, FontStyle.Bold);
                    txtCauF.ForeColor = Color.Red;
                }
                else
                {
                    txtCauF.Font = new Font(txtCauF.Font, FontStyle.Regular);
                    txtCauF.ForeColor = Color.SeaGreen;
                }
                //-------------------------------
                if (DsdapAn[0].HinhAnh != null && DsdapAn[0].HinhAnh != "")
                {
                    pic_A.ImageLocation = DsdapAn[0].HinhAnh;
                    pic_A.Visible = true;
                }
                else
                {
                    pic_A.ImageLocation = "";
                    pic_A.Visible = false;
                }
                if (DsdapAn[1].HinhAnh != null && DsdapAn[1].HinhAnh != "")
                {
                    pic_B.ImageLocation = DsdapAn[1].HinhAnh;
                    pic_B.Visible = true;
                }
                else
                {
                    pic_B.ImageLocation = "";
                    pic_B.Visible = false;
                }
                if (DsdapAn[2].HinhAnh != null && DsdapAn[2].HinhAnh != "")
                {
                    pic_C.ImageLocation = DsdapAn[2].HinhAnh;
                    pic_C.Visible = true;
                }
                else
                {
                    pic_C.ImageLocation = "";
                    pic_C.Visible = false;
                }
                if (DsdapAn[3].HinhAnh != null && DsdapAn[3].HinhAnh != "")
                {
                    pic_D.ImageLocation = DsdapAn[3].HinhAnh;
                    pic_D.Visible = true;
                }
                else
                {
                    pic_D.ImageLocation = "";
                    pic_D.Visible = false;
                }
                if (DsdapAn[4].HinhAnh != null && DsdapAn[4].HinhAnh != "")
                {
                    pic_E.ImageLocation = DsdapAn[4].HinhAnh;
                    pic_E.Visible = true;
                }
                else
                {
                    pic_E.ImageLocation = "";
                    pic_E.Visible = false;
                }
                if (DsdapAn[5].HinhAnh != null && DsdapAn[5].HinhAnh != "")
                {
                    pic_F.ImageLocation = DsdapAn[5].HinhAnh;
                    pic_F.Visible = true;
                }
                else
                {
                    pic_F.ImageLocation = "";
                    pic_F.Visible = false;
                }
                //-------------------------------
            }
        }
        private void btnSua_Click(object sender, EventArgs e)
        {
            if (listCauHoi.SelectedItems.Count == 0 || listCauHoi.SelectedItems.Count > 1)
            {
                MessageBox.Show("chọn 1 câu hỏi để sửa", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            ListViewItem itemCauHoi = listCauHoi.SelectedItems[0];
            Obj_frmCaNhan.frmChinhsuaCauhoi frm = new Obj_frmCaNhan.frmChinhsuaCauhoi(itemCauHoi.Text);
            if (frm.ShowDialog() == DialogResult.OK)
            {
                MessageBox.Show("Sửa câu hỏi thành công", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                Load_listCauhoi();
                CauHoiBll ch = new CauHoiBll();
                CauHoiTbl chtbl = new CauHoiTbl();
                chtbl = ch.ThongTinCauHoi_TheoMaCauHoi_TenCauHoi(itemCauHoi.Text, "");
                txtQuestion.Text = chtbl.NoiDung;
                RatingDoKho.Rating = chtbl.DoKho;
                lblThoigian.Text = chtbl.ThoiGian.ToString();
                Load_DapAn(itemCauHoi.Text);
            }
        }

        private void btnThem__Click(object sender, EventArgs e)
        {
            if (cboxMonHoc.Text.Trim().Length == 0 || cboChuong.Text.Trim().Length == 0)
                return;
            Obj_frmCaNhan.frmChinhsuaCauhoi frm = new Obj_frmCaNhan.frmChinhsuaCauhoi(cboxMonHoc.SelectedValue.ToString(), cboChuong.SelectedValue.ToString());
            if (frm.ShowDialog() == DialogResult.Cancel)
            {
                Load_listCauhoi();
            }
        }

        private void btnXoa_Click(object sender, EventArgs e)
        {
            if (listCauHoi.SelectedItems.Count == 0)
            {
                MessageBox.Show("Bạn chưa chọn câu hỏi", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            if (MessageBox.Show("Bạn muốn xóa câu hỏi này?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                for (int i = 0; i < listCauHoi.SelectedItems.Count; i++)
                {
                    //DapAnBll da = new DapAnBll();
                    DethiBLL dtbl = new DethiBLL();
                    
                    ListViewItem itemCauHoi = listCauHoi.SelectedItems[i];
                    CauHoiBll bll = new CauHoiBll();
                    dtbl.XoaDethiTheo_MaCauHoi(itemCauHoi.Text);
                    //da.XoaTatca_MaCauHoi(itemCauHoi.Text);
                    bll.XoaCauHoi(itemCauHoi.Text);
                }
                Load_listCauhoi();
                MessageBox.Show("Xóa Thành Công", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtCauA.Text = "";
                txtCauB.Text = "";
                txtCauC.Text = "";
                txtCauD.Text = "";
                txtCauE.Text = "";
                txtCauF.Text = "";
                txtQuestion.Text = "";
            }
        }

        private void buttonX1_Click(object sender, EventArgs e)
        {
            FrmChild.frmImport frm = new FrmChild.frmImport();
            if (frm.ShowDialog() == DialogResult.OK)
            {
                Load_listCauhoi();
                MessageBox.Show("Nhập thêm dữ liệu thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }

        private void txtFind_TextChanged(object sender, EventArgs e)
        {
            int count = listCauHoi.Items.Count;
            if (count > 0)
                for (int x = count - 1; x >= 0; x--)
                {
                    listCauHoi.Items.RemoveAt(x);
                }
            CauHoiBll bll = new CauHoiBll();
            List<CauHoiTbl> dscauhoi = new List<CauHoiTbl>();
            List<string> s = new List<string>();
            MonHocBLL mh = new MonHocBLL();
            ChuongBll chg = new ChuongBll();
            if (cboChuong.Text.Trim().Length > 0 && cboxMonHoc.Text.Trim().Length > 0)
            {
                dscauhoi = bll.TimKiemCauhoi(txtFind.Text, s, ((MonHocTbl)cboxMonHoc.SelectedItem).MaMonHoc, 0.ToString(), ((ChuongTbl)cboChuong.SelectedItem).MaChuong);
                foreach (CauHoiTbl ch in dscauhoi)
                {
                    ListViewItem lst = new ListViewItem();
                    lst.Text = ch.MaCauHoi.ToString();
                    lst.SubItems.Add(ch.NoiDung);
                    listCauHoi.Items.Add(lst);
                }
            }
        }

        private void listCauHoi_DoubleClick(object sender, EventArgs e)
        {
            if (listCauHoi.SelectedItems.Count == 0 || listCauHoi.SelectedItems.Count > 1)
                return;
            ListViewItem itemCauHoi = listCauHoi.SelectedItems[0];
            Obj_frmCaNhan.frmChinhsuaCauhoi frm = new Obj_frmCaNhan.frmChinhsuaCauhoi(itemCauHoi.Text);
            if (frm.ShowDialog() == DialogResult.OK)
            {
                Load_listCauhoi();
                CauHoiBll ch = new CauHoiBll();
                CauHoiTbl chtbl = new CauHoiTbl();
                chtbl = ch.ThongTinCauHoi_TheoMaCauHoi_TenCauHoi(itemCauHoi.Text, "");
                txtQuestion.Text = chtbl.NoiDung;
                RatingDoKho.Rating = chtbl.DoKho;
                lblThoigian.Text = chtbl.ThoiGian.ToString();
                Load_DapAn(itemCauHoi.Text);
            }
        }

        private void pic_A_Click(object sender, EventArgs e)
        {
            Obj_frmCaNhan.frmPictureView frm = new Obj_frmCaNhan.frmPictureView(pic_A.ImageLocation);
            frm.ShowDialog();
        }

        private void pic_B_Click(object sender, EventArgs e)
        {
            Obj_frmCaNhan.frmPictureView frm = new Obj_frmCaNhan.frmPictureView(pic_B.ImageLocation);
            frm.ShowDialog();
        }

        private void pic_C_Click(object sender, EventArgs e)
        {
            Obj_frmCaNhan.frmPictureView frm = new Obj_frmCaNhan.frmPictureView(pic_C.ImageLocation);
            frm.ShowDialog();
        }

        private void pic_D_Click(object sender, EventArgs e)
        {
            Obj_frmCaNhan.frmPictureView frm = new Obj_frmCaNhan.frmPictureView(pic_D.ImageLocation);
            frm.ShowDialog();
        }

        private void pic_E_Click(object sender, EventArgs e)
        {
            Obj_frmCaNhan.frmPictureView frm = new Obj_frmCaNhan.frmPictureView(pic_E.ImageLocation);
            frm.ShowDialog();
        }

        private void pic_Question_Click(object sender, EventArgs e)
        {
            Obj_frmCaNhan.frmPictureView frm = new Obj_frmCaNhan.frmPictureView(pic_Question.ImageLocation);
            frm.ShowDialog();
        }

        private void pic_F_Click(object sender, EventArgs e)
        {
            Obj_frmCaNhan.frmPictureView frm = new Obj_frmCaNhan.frmPictureView(pic_F.ImageLocation);
            frm.ShowDialog();
        }

        private void pic_A_MouseHover(object sender, EventArgs e)
        {
           
        }

        private void cboxMonHoc_KeyPress(object sender, KeyPressEventArgs e)
        {
            e.Handled = true;
        }

        private void cboChuong_KeyPress(object sender, KeyPressEventArgs e)
        {
            e.Handled = true;
        }

        

       
    }
}